package org.example.stopthreads;

/**
 * run方法没有sleep和wait
 */
public class RightWayStopThreadWithoutSleep implements Runnable {

  public static void main(String[] args) throws InterruptedException {
    Thread thread = new Thread(new RightWayStopThreadWithoutSleep());
    thread.start();
    //让线程执行1秒，然后在更改状态
    Thread.sleep(10);
    thread.interrupt();

  }

  @Override
  public void run() {
    int num = 0;
    //状态已经没有更改，并且是满足条件
    while (!Thread.currentThread().isInterrupted() && num <= Integer.MAX_VALUE / 2) {
      if (num % 10000 == 0) {
        System.out.println(num + "是1w的倍数");
      }
      num++;
    }
    System.out.println("结束执行");
  }
}
